﻿function commentfromva() {
    var Title = document.getElementById("txtTitle").value;
    if (Title == "") {
        document.getElementById("comTitle").innerHTML = "<span style='color:red;'>标题不能为空!</span>";
        return false;
    }
    else {
        document.getElementById("comTitle").innerHTML = "";
    }

    var Tag = document.getElementById("txtTag").value;
    if (Tag == "") {
        document.getElementById("comTag").innerHTML = "<span style='color:red'>标题不能为空!</span>";
        return false;
    }
    else {
        document.getElementById("comTag").innerHTML = "";
    }
}

function Specifications(dummyPath, speID, groupId, valueId, productId, isSpecial, totalCount, SpeValue) {
    if (isSpecial) {
        for (var i = 0; i < parseInt(totalCount); i++) {
            if (parseInt(valueId) == i) {
                document.getElementById(speID).className = "Special_SpecificationsSelete";
            }
            else {
                document.getElementById("SpeProperty_" + groupId + "_" + i + "").className = "Special_SpecificationsSeleted";
            }
        }
    }
    else {
        for (var i = 0; i < parseInt(totalCount); i++) {
            if (parseInt(valueId) == i) {
                document.getElementById(speID).className = "SpecificationsSelete";
            }
            else {
                document.getElementById("SpeProperty_" + groupId + "_" + i + "").className = "SpecificationsSeleted";
            }
        }
    }
    document.getElementById("SpecificationsValue" + groupId).innerHTML = SpeValue;
    document.getElementById("SpecificationsValueMake" + groupId).innerHTML = SpeValue;
    var specificationsGroup = document.getElementById("SpecificationsGroup").value;
    var SpecificationsValueStr = "";
    for (var i = 0; i < parseInt(specificationsGroup); i++) {
        if (i == parseInt(groupId)) {
            if (SpecificationsValueStr == "") {
                SpecificationsValueStr = SpeValue;
            }
            else {
                SpecificationsValueStr += "," + SpeValue;
            }
        }
        else {
            var spval = document.getElementById("SpecificationsValue" + i).innerHTML
            if (spval != "" && spval != "未选择") {
                if (SpecificationsValueStr == "") {
                    SpecificationsValueStr = spval;
                }
                else {
                    SpecificationsValueStr += "," + spval;
                }
            }
        }
    }

    //获取相册
    if (isSpecial) {
        var param = "Option=productAlumb&productId=" + productId + "&valueId=" + valueId + "";
        $.ajax({
            type: "Post",
            url: "" + dummyPath + "filehandle/product_Info.ashx",
            cache: false,
            data: param,
            success: function (msg) {
                document.getElementById("divProductAlbum").innerHTML = msg;
            }
        });
    }
    //获取商品数据
    var param = "Option=productData&productId=" + productId + "&SpecificationsValue=" + SpecificationsValueStr + "";
    $.ajax({
        type: "Post",
        url: "" + dummyPath + "filehandle/product_Info.ashx",
        cache: false,
        data: param,
        success: function (msg) {
            if (msg != "") {
                var dataArr = msg.split("v_space");
                if (dataArr.length > 3) {
                    if (document.getElementById("productShopPrice")) {
                        document.getElementById("productUnitPrice").value = dataArr[0];
                        document.getElementById("productShopPrice").innerHTML = dataArr[0];
                    }
                    //配件 
                    var spareparProductPrice = 0;
                    var cbox = document.getElementsByName("SparepartCbx");
                    if (cbox) {
                        var len = cbox.length;
                        var productIds = "";
                        var spareparProductPrice = 0;
                        for (var i = 0; i < len; i++) {
                            if (cbox[i].checked == true) {
                                if (productIds == "") {
                                    productIds = cbox[i].value;
                                }
                                else {
                                    productIds += "," + cbox[i].value;
                                }
                                var price = document.getElementById("SparepartProductPrice" + cbox[i].value).value;
                                var count = document.getElementById("SpareparProductCount" + cbox[i].value).value;
                                spareparProductPrice = parseFloat(spareparProductPrice) + parseFloat(price) * parseFloat(count);
                            }
                        }
                    }

                    var productCount = document.getElementById("ProductCount").value;
                    document.getElementById("productPriceTotal").innerHTML = parseFloat(dataArr[0]) * parseFloat(productCount) + parseFloat(spareparProductPrice);

                    if (document.getElementById("productCoodsNo")) {
                        document.getElementById("productCoodsNo").innerHTML = dataArr[3];
                    }

                    if (document.getElementById("productStock")) {
                        document.getElementById("productStock").innerHTML = dataArr[2];
                    }

                    if (document.getElementById("productIntegralPrice")) {
                        document.getElementById("productIntegralPrice").innerHTML = dataArr[1];
                    }

                }
            }
        }
    });
}

function productTotalPrice(ProductCount) {
    var price = document.getElementById("productUnitPrice").value;
    var count = ProductCount;
    if (parseInt(ProductCount) < 1) {
        count = 1;
        document.getElementById("ProductCount").value = 1;
    }
    if (price != "" && count != "") {
        //配件 
        var spareparProductPrice = 0;
        var cbox = document.getElementsByName("SparepartCbx");
        if (cbox) {
            var len = cbox.length;
            var productIds = "";
            var spareparProductPrice = 0;
            for (var i = 0; i < len; i++) {
                if (cbox[i].checked == true) {
                    if (productIds == "") {
                        productIds = cbox[i].value;
                    }
                    else {
                        productIds += "," + cbox[i].value;
                    }
                    var SparepartProductPrice = document.getElementById("SparepartProductPrice" + cbox[i].value).value;
                    var SpareparProductCount = document.getElementById("SpareparProductCount" + cbox[i].value).value;
                    spareparProductPrice = parseFloat(spareparProductPrice) + parseFloat(SparepartProductPrice) * parseFloat(SpareparProductCount);
                }
            }
        }
        document.getElementById("productPriceTotal").innerHTML = parseFloat(price) * parseFloat(count) + parseFloat(spareparProductPrice);
    }
}

function AddCarShop(path, productId) {
    //规格信息
    var spcGroupCount = document.getElementById("SpecificationsGroup").value;
    var SpecificationsValueStr = "";
    for (var i = 0; i < parseInt(spcGroupCount); i++) {
        if (document.getElementById("SpecificationsValueMake" + i)) {
            var val = document.getElementById("SpecificationsValueMake" + i).innerHTML;
            if (val != "" && val == "未选择") {
                var title = document.getElementById("SpecificationsTitle" + i).innerHTML;
                alert("温馨提示：请选择" + title);
                return false;
            }
            else {
                if (SpecificationsValueStr == "") {
                    SpecificationsValueStr = val;
                }
                else {
                    SpecificationsValueStr += "," + val;
                }
            }
        }
    }
    //商品数量
    var productCount = 1;
    if (document.getElementById("ProductCount")) {
        productCount = document.getElementById("ProductCount").value
    }

    //配件信息
    var cbox = document.getElementsByName("SparepartCbx");
    var fittingsProductId = "";
    var fittingsProductCount = "";
    if (cbox) {
        var len = cbox.length;
        var spareparProductPrice = 0;
        for (var i = 0; i < len; i++) {
            if (cbox[i].checked == true) {
                if (fittingsProductId == "") {
                    fittingsProductId = cbox[i].value;
                    fittingsProductCount = document.getElementById("SpareparProductCount" + cbox[i].value).value;
                }
                else {
                    fittingsProductId += "," + cbox[i].value;
                    fittingsProductCount += "," + document.getElementById("SpareparProductCount" + cbox[i].value).value;
                }
            }
        }
    }
    var sparepartId = "";
    if (document.getElementById("SparepartId")) {
        sparepartId = document.getElementById("SparepartId").value;
    }
    window.location.href = path + "product/shoppingcart.aspx?q_productid=" + productId + "&q_proCount=" + productCount + "&q_proSpecification=" + SpecificationsValueStr + "&q_fittingsProId=" + fittingsProductId + "&q_fittingsProCount=" + fittingsProductCount + "&q_proSpareparId=" + sparepartId + "";
}

function FittingShopCar(Path, productId) {
    var productCount = document.getElementById("SpareparProductCount" + productId).value;
    var sparepartId = "";
    if (document.getElementById("SparepartId")) {
        sparepartId = document.getElementById("SparepartId").value;
    }
    window.location.href = Path + "product/shoppingcart.aspx?q_productid=" + productId + "&q_proCount=" + productCount + "&q_proSpareparId=" + sparepartId + "";
}

function Sparepar(productId, minCount, maxCount) {
    var cbox = document.getElementsByName("SparepartCbx");
    var len = cbox.length;
    var productIds = "";
    var spareparProductPrice = 0;
    var SpareparProductCount = document.getElementById("SpareparProductCount" + productId).value
    if (IsNumeric(SpareparProductCount) == false || parseInt(SpareparProductCount) < minCount || parseInt(SpareparProductCount) > maxCount) {
        document.getElementById("SpareparProductCount" + productId).value = minCount;
    }
    for (var i = 0; i < len; i++) {
        if (cbox[i].checked == true) {
            if (productIds == "") {
                productIds = cbox[i].value;
            }
            else {
                productIds += "," + cbox[i].value;
            }
            var price = document.getElementById("SparepartProductPrice" + cbox[i].value).value;
            var count = document.getElementById("SpareparProductCount" + cbox[i].value).value;
            spareparProductPrice = parseFloat(spareparProductPrice) + parseFloat(price) * parseFloat(count);
        }
    }
    if (document.getElementById("productPriceTotal")) {
        var productPrice = document.getElementById("productUnitPrice").value;
        var productCount = document.getElementById("ProductCount").value
        if (productPrice != "" && productCount != "") {
            document.getElementById("productPriceTotal").innerHTML = parseFloat(spareparProductPrice) + parseFloat(productPrice) * parseFloat(productCount);
        }
    }
}
function IsNumeric(port) {
    var pattern = /^\d+$/;
    if (!pattern.test(port))
        return false;
    return true;
}